package com.example.a79273.shandianban;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class NameSetActivity extends AppCompatActivity implements View
        .OnClickListener {
private EditText et_setting_name;
    private TextView tv_name_set_save;
    private ImageView iv_name_set_back;
    private String name1;
    private Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_name_set);
        initView();
        initData();
        setListener();
    }

    private void initData() {
        intent = getIntent();
        name1 = intent.getStringExtra("name1");
        et_setting_name.setText(name1);
    }

    private void setListener() {
        iv_name_set_back.setOnClickListener(this);
        tv_name_set_save.setOnClickListener(this);
    }


    private void initView() {
        et_setting_name= (EditText) findViewById(R.id.et_setting_name);
        tv_name_set_save= (TextView) findViewById(R.id.tv_name_set_save);
        iv_name_set_back= (ImageView) findViewById(R.id.iv_name_set_back);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case  R.id.tv_name_set_save:
                String name2 = et_setting_name.getText().toString().trim();

                if(name1.equals(name2)){
                    Toast.makeText(NameSetActivity.this, "内容没有更改", Toast.LENGTH_SHORT).show();
                }else {
                    intent.putExtra("name2",name2);
                    setResult(2,intent);
                    finish();
                }
                break;
            case R.id.iv_name_set_back:
                finish();
                break;
        }


    }
}
